home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / misc / vinced / include / vnc / dynamics.h next >
C/C++ Source or Header  |  1999-04-19  |  9KB  |  247 lines

  1. #ifndef VNC_DYNAMICS_H
  2. #define VNC_PYNAMICS_H
  3. /*********************************************************
  4.  ** ViNCEd                                              **
  5.  ** a DOS - window handler                              **
  6.  **                                                     **
  7.  ** © 1991-98 THOR-Software inc.                        **
  8.  ** Version 3.60                                        **
  9.  **                                                     **
  10.  ** program version 3.60 20 Aug 1998 THOR                **
  11.  **                                                     **
  12.  ** ViNCEd dynamical memory management                  **
  13.  **-----------------------------------------------------**
  14.  **                                                     **
  15.  ** all use at your own risk,etc.,etc.                  **
  16.  **                                                     **
  17.  ** Everything declared as "reserved" or                **
  18.  ** "not used" is NOT free for your use,                **
  19.  ** it will propably used in a later release.           **
  20.  ** All FREE entries are free for public                **
  21.  ** use and are, if not otherwise noticed,              **
  22.  ** initialized as ZERO                                 **
  23.  *********************************************************/
  24.  
  25. #ifndef EXEC_TYPES_H
  26. #include <exec/types.h>
  27. #endif
  28.  
  29. /* This file is about the dynamical memory nodes.
  30.    Unlike all exec memory, these chunks of memory MIGHT GET MOVED THRU
  31.    SPACE if more room is needed!
  32.  
  33.    SPECIAL CARE MUST BE TAKEN TO HOLD POINTERS ON THESE, SINCE THE
  34.    POINTERS GET INVALID WHEN THESE STRUCTURES ARE TRAVELING!
  35.  
  36.    IF YOU NEED A POINTER TO THEM, STORE IT EITHER IN THE ViNCUserNode
  37.    (see vnc/window.h), OR IN A LINKED LIST. THESE POINTERS GET "BEND"
  38.    AUTOMATICALLY IF THE NODES MOVE AROUND.
  39.  
  40.    IF YOU REMOVE A DYNAMICAL NODE FROM A LIST, MAKE SHURE THAT YOU
  41.    SET THE LINK POINTERS TO ZERO!
  42.  
  43.    BE WARNED! HANDLING WITH THEM IS TRICKY!
  44. */
  45.  
  46. /* An occupied piece of memory, doubly linked for easy freeing and
  47.    garbage collection */
  48.  
  49. struct DynNode {
  50.         struct DynNode                  *dynnd_succ;
  51.         struct DynNode                  *dynnd_pred;    /* linked in
  52.                                                            UsedList */
  53.         UWORD                            dynnd_size;    /* size, including
  54.                                                            structure */
  55. };
  56.  
  57.  
  58. /* Note that the size is needed in case this one must move thru memory,
  59.    for copying it to the destination. The MemBlock ptr is used for fast
  60.    freeing of the structure */
  61.  
  62.  
  63. /* A part of a line on the screen or in the history. */
  64. struct LineBody {
  65.         struct LineBody                 *vln_succln;
  66.         struct LineBody                 *vln_predln;    /* linked list */
  67.         UBYTE                            vln_Status;    /* see below */
  68.         UBYTE                            vln_RasterMask;/* used bitplanes
  69.                                                            for this line
  70.                                                            for quick
  71.                                                            scrolling */
  72.         UBYTE                            vln_PackedPenPair;
  73.                                                         /* A and BPen of
  74.                                                            the first word */
  75.         UBYTE                            vln_PackedType;
  76.                                                         /* Drawmode &
  77.                                                            algostyle */
  78. };
  79.  
  80. /* This is how a line is allocated from memory, and how it's hold */
  81.  
  82. struct DynLine {
  83.         struct DynNode          vline_header;
  84.         struct LineBody         vline_body;
  85. };
  86.  
  87. /* The allocation is done by AllocLine(), FreeLine(). The size given
  88.    to AllocLine is the number of ADDITIONAL BYTES you need, except
  89.    this structure.
  90. */
  91.  
  92. /* How to get the pointer to the first word of a line, i.e. its contents: */
  93.  
  94. #define VLINE_FIRSTWORD(lin)    ((struct ViWord *)((lin)+1));
  95.  
  96. /* REMEMBER THAT LINES LIKE ALL DYNAMICAL NODE STUFF WILL MOVE THRU
  97.    MEMORY. THERE ISN'T A SINGLE BIT IN THE SYSTEM TO PREVENT THEM
  98.    FROM DOING SO! */
  99.  
  100. /* How the pen pairs are packed:
  101.         The upper nibble of the PackedPenPair is the BPen
  102.         (colors 0..15 in bits 7..4)
  103.         The lower nibble is the APen.
  104.         This is the reason why ViNCEd is limited to sixteen
  105.         colors */
  106.  
  107. #define PP_PENMASK      0x0F;
  108. #define PP_BPENSHIFT    4;
  109.  
  110. /* Shift left by BPENSHIFT to get the BPEN, then and with mask */
  111.  
  112. /* How the AlgoStyle is packed: */
  113.  
  114. /* keeps the draw mode for gfx */
  115. #define PA_DRAWMASK     0x06
  116.  
  117. /* must be and-ed to turn on JAM2 */
  118. #define PA_DRAWORF      0x01
  119.  
  120. /* shift by this number to get the algostyle */
  121. #define PA_SOFTSHIFT    3
  122.  
  123. /* use this mask to get the algostyle */
  124. #define PA_SOFTMASK     0x07
  125.  
  126. /* the following bits have a special meaning */
  127.  
  128. /* set if part of the marked block */
  129. #define PA_INBLOCK_BIT          6
  130. #define PA_INBLOCK_MASK         (1L<<6)
  131.  
  132. /* set if not user input, but printed by DOS (ignore on input) */
  133. #define PA_PRINT_BIT            7
  134. #define PA_PRINT_MASK           (1L<<7)
  135.  
  136. /* vln_status bits */
  137.  
  138. /* this was the line the DOS put the cursor in */
  139. #define VLN_DOSLINE_BIT         1
  140. #define VLN_DOSLINE_MASK        (1L<<1)
  141.  
  142. /* this is set if the line end is marked to be in the block as well */
  143. #define VLN_CRADDED_BIT         2
  144. #define VLN_CRADDED_MASK        (1L<<2)
  145.  
  146. /* the next three are reserved for foldings. Not yet used, however */
  147. #define VLN_INFOLD_BIT          3
  148. #define VLN_INFOLD_MASK         (1L<<3)
  149. #define VLN_STARTFOLD_BIT       4
  150. #define VLN_STARTFOLD_MASK      (1L<<4)
  151. #define VLN_ENDFOLD_BIT         5
  152. #define VLN_ENDFOLD_MASK        (1L<<5)
  153.  
  154. /* this one is set if the line is part of a marked block */
  155. #define VLN_INBLOCK_BIT         6
  156. #define VLN_INBLOCK_MASK        (1L<<6)
  157.  
  158. /* set if the complete line contains no user input */
  159. #define VLN_PRINT_BIT           7
  160. #define VLN_PRINT_MASK          (1L<<7)
  161.  
  162.  
  163. /* The snip documentation is removed from this file. The snip
  164.    structures have changed and are now PRIVATE. */
  165.  
  166.  
  167. /* The next two represent a line in the output buffer of ViNCEd.
  168.    Again, AllocLine() and FreeLine() are used to allocate/free them,
  169.    and again a dynamical node is used for allocation.
  170.    The size is again the same as the LineBody!
  171.    BEWARE: THIS WILL MOVE THRU MEMORY IF NEEDED ! */
  172.  
  173. struct OutNodeBody {
  174.         struct OutNodeBody      *von_succ;
  175.         struct OutNodeBody      *von_pred;      /* again, doubly
  176.                                                    linked list */
  177.         UWORD                    von_TextSize;  /* readable characters
  178.                                                    in here */
  179.         UWORD                    von_Offset;    /* offset from beginning
  180.                                                    of the output buffer */
  181. };
  182.  
  183. /* And this is how it looks like in memory */
  184.  
  185. struct DynOutNode {
  186.         struct DynNode          doutn_header;
  187.         struct OutNodeBody      doutn_body;
  188. };
  189.  
  190.  
  191. /* Use this macro to get the first character in here */
  192. #define DOUTN_FIRSTCHAR(on)     ((char *)((on)+1))
  193.  
  194.  
  195. /* This is the word structure I mentioned above.
  196.    Unlike what you might think, it does not hold a "word" in the common
  197.    sense, but a sequence of characters of the same pens and draw
  198.    modes. Big areas of blank spaces are not hold in the word structures
  199.    as well, since they only eat up memory. They are removed from the
  200.    lines, and the word position is adjusted.
  201.    This is the ViNCEd way to compress its contents. */
  202.  
  203. struct ViWord {
  204.         UBYTE           vwd_size;       /* size of word in characters.
  205.                                            zero if this is the last word
  206.                                            in a line */
  207.         UBYTE           vwd_PackedPenPair;      /* PP, packed like in
  208.                                                    lines */
  209.         UBYTE           vwd_PackedType; /* DrawMode and style, again
  210.                                            packed like above */
  211.         UBYTE           vwd_XPos;       /* absolute position in the line */
  212. };
  213.  
  214. /*How to get the contents of a ViWord: */
  215.  
  216. #define WORD_BODY(wd)   ((char *)((wd)+1))
  217.  
  218. /*And how to get the next word */
  219.  
  220. #define NEXT_WORD(wd)   ((struct ViWord *)(WORD_BODY((wd))+(wd->vwd_size)))
  221.  
  222.  
  223. /* The maximum size of a line */
  224. #define VLINE_MAXLENGTH         243
  225. #define VLINE_ML                (VLINE+MAXLENGTH+1)
  226.  
  227. /* Additional room */
  228. #define VCHAR_SIZE              258
  229.  
  230. /* The next one is not dynamic, and holds an uncompressed line */
  231. struct VCharLine {
  232.         char            vch_char[VCHAR_SIZE];
  233.         struct {
  234.                 UBYTE vch_PackedPenPair;
  235.                 UBYTE vch_PackedType;
  236.         }               vch_Types[VCHAR_SIZE];
  237. };
  238.  
  239.  
  240. /* VCharLines are easier to handle, DynLines take up less memory and are
  241.    used everywhere else except for the current editor line (the line under
  242.    the cursor).
  243.    Use LineToLinear() and LinearToAlloc()/LinearToLine() to convert between
  244.    the types. */
  245.  
  246. #endif
  247.